package com.mdlib.helper.base;

import com.mdlib.helper.ui.dialog.HelperWaitDialog;
import com.mdlib.helper.ui.widget.LoginLoadingDialog;

import rx.Subscription;
import rx.subscriptions.CompositeSubscription;


/**
 * Created by librabin on 16/10/22.
 */

public abstract class BaseAppFragment extends BaseFragment {


    private CompositeSubscription compositeSubscription;

    public void addSubscribe(Subscription subscription) {
        if (compositeSubscription == null) {
            compositeSubscription = new CompositeSubscription();

        }
        compositeSubscription.add(subscription);
    }

    public void unSubscribe() {
        if (compositeSubscription != null) {
            compositeSubscription.unsubscribe();
            compositeSubscription = null;
        }
    }


    protected boolean canUpate = true;


    public LoginLoadingDialog loginLoadingDialog;
    public HelperWaitDialog helperWaitDialog;

    /**
     * 创建Dialog对象
     *
     * @param msg
     * @param isblack
     */
    public void startLoginLoadDialog(String msg, boolean isblack) {
        loginLoadingDialog = new LoginLoadingDialog(getActivity(), msg, isblack);
        loginLoadingDialog.show();
    }

    public void startLoadingDialog(boolean isblack) {
        helperWaitDialog = new HelperWaitDialog(getActivity(), isblack);
        helperWaitDialog.show();
    }


    /**
     * 关闭Dialog对象
     */
    public void stopLoginingDialog() {
        if (loginLoadingDialog != null) {
            loginLoadingDialog.close();
        }
    }

    public void stopLoadDialog() {

        if (helperWaitDialog != null) {
            helperWaitDialog.close();
        }
    }


    @Override
    public void onDestroyView() {
        unSubscribe();
        super.onDestroyView();
    }
}
